//
//  RootViewController.m
//  TongMiBaby
//
//  Created by 史伟文 on 15/4/2.
//  Copyright (c) 2015年 XuanRuiTechnology. All rights reserved.
//

#import "RootViewController.h"
#import "FirstPageViewController.h"
#import "MessageViewController.h"
#import "BulletinViewController.h"
#import "RecommendationViewController.h"
#import "MemberCenterViewController.h"
#import "XRNavigationController.h"
@implementation RootViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self loadEachChildViewController];
}

- (void)loadEachChildViewController
{
    [self initChildViewCotroller:[[FirstPageViewController alloc] init] title:@"首页" image:[UIImage imageNamed:@"icon_首页_未选中"] selectedImage:[UIImage imageNamed:@"icon_首页_选中"]];
    
    [self initChildViewCotroller:[[MessageViewController alloc] init] title:@"消息" image:[UIImage imageNamed:@"icon_消息_未选中"] selectedImage:[UIImage imageNamed:@"icon_消息_选中"]];
    
    [self initChildViewCotroller:[[BulletinViewController alloc] init] title:@"公告" image:[UIImage imageNamed:@"icon_公告_未选中"] selectedImage:[UIImage imageNamed:@"icon_公告_选中"]];
    
    [self initChildViewCotroller:[[RecommendationViewController alloc] init] title:@"推荐" image:[UIImage imageNamed:@"icon_推荐_未选中"] selectedImage:[UIImage imageNamed:@"icon_推荐_选中"]];
    
    [self initChildViewCotroller:[[MemberCenterViewController alloc] init] title:@"我的" image:[UIImage imageNamed:@"icon_我的_未选中"] selectedImage:[UIImage imageNamed:@"icon_我的_选中"]];
}

// 创建一个tab控制器的栏目
- (void)initChildViewCotroller:(UIViewController *)controller title:(NSString *)title image:(UIImage *)image selectedImage:(UIImage *)selectedImage
{
    // 设置tabbar上面图标的样式
    NSDictionary *normalAttributeDict = @{
                                          NSForegroundColorAttributeName:[UIColor grayColor],
                                          NSFontAttributeName:[UIFont fontWithName:HEITIMEDIUM size:12]
                                          };
    NSDictionary *highlightAttributeDict = @{
                                             NSForegroundColorAttributeName:[UIColor orangeColor],
                                             NSFontAttributeName:[UIFont fontWithName:HEITIMEDIUM size:12]
                                             };
    [[UITabBarItem appearance] setTitleTextAttributes:normalAttributeDict forState:UIControlStateNormal];
    [[UITabBarItem appearance] setTitleTextAttributes:highlightAttributeDict forState:UIControlStateSelected];
    
    controller.tabBarItem.title = title;
    controller.tabBarItem.image = image;
    controller.tabBarItem.selectedImage = [selectedImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    // 给每一个控制器套上导航功能
    UINavigationController *navi = [[UINavigationController alloc] initWithRootViewController:controller];
    [self addChildViewController:navi];
}


@end
